#创建浏览器对象
import datetime
import os.path
import sys
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.edge.service import Service
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
edge_path=r"E:\Users\zzj20\Desktop\edgedriver_win64_140.0.3485.54\msedgedriver.exe"
class Driver:
    driver=""
    #注册时保证每一次不重复
    name = datetime.datetime.now().strftime("%Y%m%d%H%M%S")

    def __init__(self):
        options=webdriver.EdgeOptions()
        self.driver=webdriver.Edge(service=Service(edge_path),options=options)
        self.driver.implicitly_wait(50)
    def getScreenShot(self):
        #创建屏幕截图
        #图片文件名称：./2025-08-19-171723.png
        #图片路径：../images/2025-08-19/2025-08-19-171723.png
        dirname=datetime.datetime.now().strftime("%Y-%m-%d")
        #判断dirname文件夹是否已经存在，若不存在则创建文件夹
        if not os.path.exists("../images/"+dirname):
            os.mkdir("../images/"+dirname)
        #2025-08-19/2025-08-19-171723.png
        #图片路径：../images/2025-08-19/2025-08-19-171723.png
        filename=sys._getframe().f_back.f_code.co_name+"-"+datetime.datetime.now().strftime("%Y-%m-%d-%H%M%S")+".png"
        self.driver.save_screenshot("../images/"+dirname+"/"+filename)
    def Login(self):
        # 输入账号
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("zzj24")
        # 输入密码
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123456")
        # 点击登录
        self.driver.find_element(By.CSS_SELECTOR,"#root > div > div.content___2zk1- > div.main___x4OjT > div > form > button").click()
        self.driver.maximize_window()

    def Exit(self):
        wait = WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR,
                                                                                      "#sk-layout > div > div > section > div.ant-pro-layout-container > header.ant-layout-header.ant-pro-layout-header.ant-pro-layout-header-fixed-header.ant-pro-layout-header-mix.ant-pro-layout-header-fixed-header-action.ant-pro-layout-header-header > div > div.ant-pro-global-header-right-content > div > div > div > div:nth-child(2) > span")))
        self.driver.find_element(By.CSS_SELECTOR,"#sk-layout > div > div > section > div.ant-pro-layout-container > header.ant-layout-header.ant-pro-layout-header.ant-pro-layout-header-fixed-header.ant-pro-layout-header-mix.ant-pro-layout-header-fixed-header-action.ant-pro-layout-header-header > div > div.ant-pro-global-header-right-content > div > div > div > div:nth-child(2) > span").click()
        wait = WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR,
                                                                                      "body > div:nth-child(10) > div > div > ul > li:nth-child(4)")))
        self.driver.find_element(By.CSS_SELECTOR,"body > div:nth-child(10) > div > div > ul > li:nth-child(4)").click()


WJDriver=Driver()